import * as apis from '@/services/ReturnMoneyValueMgr';
import _ from 'lodash';
import moment from 'moment';
import { router } from 'umi';

const Model = {
  namespace: 'PayBackModulus',
  state: {
    versionActive: null, // 当前版本obj
    versionList: [], // 版本列表
  },
  effects: {
    // 获取版本列表
    *getVersionsList({ payload, callback }, { call, put }) {
      const params = { ...payload };
      const res = yield call(apis.getReturnVersionListUsingGET, { params });
      if (!res || res.code !== 1) {
        // 如果该项目没有调整版
        yield put({ type: 'save', payload: { versionList: [], versionActive: null } });
        if (callback) callback();
        return;
      }
      const data = res.data.map(tar => {
        const { projectReturnCoefficient, createUser } = tar;
        return { ...projectReturnCoefficient, createUser };
      });
      const firstVersion = data[0];
      yield put({ type: 'save', payload: { versionList: data, versionActive: firstVersion } });
      if (callback) callback(firstVersion);
      //   const { level1, level2, project, stage, category } = payload.match.params;
    },
  },
  reducers: {
    save(state, action) {
      console.log('action.payload=', action.payload);
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
